package es.nadalgoyo.frikiquest.control;

import android.content.Context;
import android.text.InputType;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import es.nadalgoyo.frikiquest.R;
import es.nadalgoyo.frikiquest.control.style.Fonts;

public class TextButton extends AbstractControl {

	private EditText textEdit;

	private Button boton;

	private OnClickListener listener;

	private String buttonText = null;

	private boolean isNumeric = false;

	public TextButton(Context context) {
		super(context);
	}

	public TextButton(Context context, AttributeSet att) {
		super(context, att);
	}

	public EditText getTextEdit() {
		return textEdit;
	}

	@Override
	public void inicializar() {
		String infService = Context.LAYOUT_INFLATER_SERVICE;
		LayoutInflater li = (LayoutInflater) getContext().getSystemService(
				infService);

		li.inflate(R.layout.puntuador, this, true);
		textEdit = (EditText) findViewById(R.id.TxtGuardarPuntos);
		textEdit.setTypeface(Fonts.getLordOfTheRings(getAssets()));
		if (isNumeric)
			textEdit.setInputType(InputType.TYPE_CLASS_NUMBER);

		boton = (Button) findViewById(R.id.BtnGuardar);
		if (buttonText != null)
			boton.setText(buttonText);

		boton.setTypeface(Fonts.getStarTrek(getAssets()));
		asignarEventos();
	}

	public void addOnClickListener(OnClickListener listener) {
		this.listener = listener;
	}

	private void asignarEventos() {
		boton.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				listener.onClick();
			}
		});
	}

	public void setIsNumeric(boolean is) {
		isNumeric = is;
	}

	public void setButtonText(String text) {
		this.buttonText = text;
	}

	public interface OnClickListener {
		public void onClick();
	}
}